package com.zxw.user.event;

import com.zxw.common.entity.user.UserVO;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

/**
 * 第二步：执行用户登录，并发布事件
 * 参考：https://blog.csdn.net/qq_28060549/article/details/81073001
 */
@Service
public class UserLoginService implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher applicationEventPublisher;

    public boolean register(UserVO userVO) {

        //用户登录
        System.out.println("[service]用户[" + userVO + "]注册成功！");

        //消息发布
        applicationEventPublisher.publishEvent(new UserLoginEvent(this, userVO));

        return true;
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }
}
